/*
 * ColTitleFrame.java
 *
 * --- Last Update: 4/17/2010 11:46 AM ---
 *
 * Update Notes 4/17/2010 11:46 AM by Adrian Wijasa:
 * This version is made to work with Java 5.
 *
 * Created on March 14, 2007, 3:15 PM
 *
 * CSV Loader
 * Copyright 2007, 2009, 2010 Adrian Wijasa
 *
 * This file is part of CSV Loader.
 *
 * CSV Loader is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * CSV Loader is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with CSV Loader.  If not, see <http://www.gnu.org/licenses/>.
 */

package forms;

import csv.CSVReader;
import javax.swing.ButtonGroup;

/**
 * Ask the user if the CSV File contains column titles
 *
 * @author matianyuan
 */
public class ColTitleFrame extends javax.swing.JFrame {

    /** Creates new form ColTitleFrame5 */
    public ColTitleFrame( Main main ) {
        this.main = main;
        initComponents();
        initButtonGroup();
        setLocation( main.getX() + 268, main.getY() + 251 );
    }

    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        colTitleLabel = new javax.swing.JLabel();
        csvRadioButton = new javax.swing.JRadioButton();
        manualRadioButton = new javax.swing.JRadioButton();
        okLabel = new javax.swing.JLabel();

        setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);
        setTitle("Column TItle Naming");
        addWindowListener(new java.awt.event.WindowAdapter() {
            public void windowClosed(java.awt.event.WindowEvent evt) {
                formWindowClosed(evt);
            }
        });

        colTitleLabel.setText("Please Identify the Source of Column Title Naming:");

        csvRadioButton.setText("The First Line of CSV File");
        csvRadioButton.setBorder(javax.swing.BorderFactory.createEmptyBorder(0, 0, 0, 0));
        csvRadioButton.setMargin(new java.awt.Insets(0, 0, 0, 0));

        manualRadioButton.setText("Will be Entered Manually");
        manualRadioButton.setBorder(javax.swing.BorderFactory.createEmptyBorder(0, 0, 0, 0));
        manualRadioButton.setMargin(new java.awt.Insets(0, 0, 0, 0));

        okLabel.setFont(new java.awt.Font("Dialog", 1, 11)); // NOI18N
        okLabel.setForeground(new java.awt.Color(0, 102, 255));
        okLabel.setText("OK");
        okLabel.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                okLabelMouseClicked(evt);
            }
            public void mouseEntered(java.awt.event.MouseEvent evt) {
                okLabelMouseEntered(evt);
            }
            public void mouseExited(java.awt.event.MouseEvent evt) {
                okLabelMouseExited(evt);
            }
        });

        org.jdesktop.layout.GroupLayout layout = new org.jdesktop.layout.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
            .add(layout.createSequentialGroup()
                .addContainerGap()
                .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
                    .add(colTitleLabel)
                    .add(csvRadioButton)
                    .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.TRAILING)
                        .add(okLabel)
                        .add(manualRadioButton)))
                .addContainerGap(45, Short.MAX_VALUE))
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
            .add(layout.createSequentialGroup()
                .addContainerGap()
                .add(colTitleLabel)
                .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
                .add(csvRadioButton)
                .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
                .add(manualRadioButton)
                .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
                .add(okLabel)
                .addContainerGap(org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents

    private void okLabelMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_okLabelMouseClicked
        okLabel.setForeground( main.red );

        try {
            new CSVReader( main, manualRadioButton.isSelected() );
        } catch( Exception e ) { e.printStackTrace(); }

        main.fileChooser.disposeFileChooser();
        dispose();
}//GEN-LAST:event_okLabelMouseClicked

    private void okLabelMouseExited(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_okLabelMouseExited
        okLabel.setForeground( main.blue );
}//GEN-LAST:event_okLabelMouseExited

    private void okLabelMouseEntered(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_okLabelMouseEntered
        okLabel.setForeground( main.black );
}//GEN-LAST:event_okLabelMouseEntered

    private void formWindowClosed(java.awt.event.WindowEvent evt) {//GEN-FIRST:event_formWindowClosed
        main.fileChooser.setEnabled( true );
        main.fileChooser.requestFocus();
    }//GEN-LAST:event_formWindowClosed

    private void initButtonGroup() {
        buttonGroup = new ButtonGroup();
        buttonGroup.add( csvRadioButton );
        buttonGroup.add( manualRadioButton );
        csvRadioButton.setSelected( true );
    }

    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JLabel colTitleLabel;
    private javax.swing.JRadioButton csvRadioButton;
    private javax.swing.JRadioButton manualRadioButton;
    private javax.swing.JLabel okLabel;
    // End of variables declaration//GEN-END:variables

    private ButtonGroup buttonGroup;
    private Main main;
}
